package com.mpsc.api.unit;

public class Test {

    public static void main(String[] args) {
        String[] strs = {"1G", "2G", "1024M"};
        test(3, strs);

    }

    private static void test(int size, String[] strs) {

        String temp;
        for (int i = 0; i < size; i++) {
            for (int j = i + 1; i < size; i++) {
                if (flag(strs[i], strs[j])) {
                    temp = strs[i];
                    strs[i] = strs[j];
                    strs[j] = temp;
                }
            }
        }
        for (int i = 0; i < size; i++) {
            System.out.println(strs[i]);
        }
    }

    private static boolean flag(String s1, String s2) {
        int a1 = Integer.parseInt(s1.substring(0, s1.length() - 1)), a2 = Integer.parseInt(s2.substring(0, s2.length() - 1));
        if (s1.contains("T")) {
            a1 = a1 * 1024 * 1024;
        } else if (s1.contains("G")) {
            a1 = a1 * 1024;
        }

        if (s1.contains("T")) {
            a2 = a2 * 1024 * 1024;
        } else if (s1.contains("G")) {
            a2 = a2 * 1024;
        }
        return a1 > a2;
    }

}
